| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | $(function() { |
||
| 2 | var newData; |
||
| 3 | |||
| 4 | $('.tools-table').on('click', '.tools-toggle', function () { |
||
| 5 | if (!newData) { |
||
| 6 | // countsByTool must be cloned |
||
| 7 | newData = Object.assign({}, window.countsByTool); |
||
| 8 | } |
||
| 9 | |||
| 10 | var index = $(this).data('index'), |
||
| 11 | tool = $(this).data('tool'), |
||
| 12 | $row = $(this).parents('tr'); |
||
|
|
|||
| 13 | |||
| 14 | // must use .attr instead of .prop as sorting script will clone DOM elements |
||
| 15 | if ($(this).attr('data-disabled') === 'true') { |
||
| 16 | newData[tool] = window.countsByTool[tool]; |
||
| 17 | window.toolsChart.data.datasets[0].data[index] = parseInt(newData[tool], 10); |
||
| 18 | $(this).attr('data-disabled', 'false'); |
||
| 19 | } else { |
||
| 20 | delete newData[tool]; |
||
| 21 | window.toolsChart.data.datasets[0].data[index] = null; |
||
| 22 | $(this).attr('data-disabled', 'true'); |
||
| 23 | } |
||
| 24 | |||
| 25 | // gray out row in table |
||
| 26 | $(this).parents('tr').toggleClass('excluded'); |
||
| 27 | |||
| 28 | // change the hover icon from a 'x' to a '+' |
||
| 29 | $(this).find('.glyphicon').toggleClass('glyphicon-remove').toggleClass('glyphicon-plus'); |
||
| 30 | |||
| 31 | // update stats |
||
| 32 | var total = 0; |
||
| 33 | Object.keys(newData).forEach(function (tool) { |
||
| 34 | total += parseInt(newData[tool], 10); |
||
| 35 | }); |
||
| 36 | var toolsCount = Object.keys(newData).length; |
||
| 37 | $('.tools--tools').text( |
||
| 38 | toolsCount.toLocaleString() + " " + |
||
| 39 | $.i18n('num-tools', toolsCount) |
||
| 40 | ); |
||
| 41 | $('.tools--count').text(total.toLocaleString()); |
||
| 42 | |||
| 43 | window.toolsChart.update(); |
||
| 44 | }); |
||
| 45 | |||
| 46 | if ($('.non-auto-edits-container')[0]) { |
||
| 47 | $.getJSON('/api/nonautomated_edits/en.wikipedia.org/L235/all/0').then(function (data) { |
||
| 48 | $('.non-auto-edits-container').html(data.markup); |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | }); |
||
| 52 |